#ifndef SETTINGSWIDGET_H
#define SETTINGSWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QGroupBox>
#include <QComboBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QPushButton>
#include <QLabel>
#include <QSlider>
#include <QLineEdit>
#include <QTextEdit>
#include <QTabWidget>
#include <QSettings>
#include "authservice.h"

class SettingsWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SettingsWidget(AuthService *authService, QWidget *parent = nullptr);
    virtual ~SettingsWidget();

signals:
    void settingsChanged();
    void themeChanged(const QString &theme);

private slots:
    void onSaveClicked();
    void onResetClicked();
    void onChangePasswordClicked();
    void onLogoutAllDevicesClicked();
    void onThemeChanged();
    void onLanguageChanged();
    void onAutoRefreshToggled(bool enabled);
    void onRefreshIntervalChanged(int seconds);
    void onNotificationToggled(bool enabled);

private:
    void setupUI();
    void setupGeneralTab();
    void setupGameTab();
    void setupAccountTab();
    void setupAboutTab();
    void loadSettings();
    void saveSettings();
    void resetToDefaults();
    void applyStyles();
    void updateUserInfo();

    AuthService *m_authService;

    // UI组件
    QVBoxLayout *m_mainLayout;
    QTabWidget *m_tabWidget;

    // 通用设置
    QWidget *m_generalTab;
    QComboBox *m_themeCombo;
    QComboBox *m_languageCombo;
    QCheckBox *m_autoStartCheck;
    QCheckBox *m_minimizeToTrayCheck;
    QCheckBox *m_notificationCheck;

    // 游戏设置
    QWidget *m_gameTab;
    QComboBox *m_defaultGameTypeCombo;
    QComboBox *m_defaultRegionCombo;
    QComboBox *m_serverPreferenceCombo;
    QCheckBox *m_autoRefreshCheck;
    QSpinBox *m_refreshIntervalSpin;
    QSlider *m_maxPingSlider;
    QLabel *m_maxPingLabel;

    // 账户设置
    QWidget *m_accountTab;
    QLabel *m_usernameLabel;
    QLabel *m_emailLabel;
    QLabel *m_lastLoginLabel;
    QLabel *m_loginCountLabel;
    QPushButton *m_changePasswordButton;
    QPushButton *m_logoutAllButton;

    // 关于页面
    QWidget *m_aboutTab;
    QLabel *m_appNameLabel;
    QLabel *m_versionLabel;
    QLabel *m_buildDateLabel;
    QTextEdit *m_aboutText;

    // 按钮
    QPushButton *m_saveButton;
    QPushButton *m_resetButton;

    // 设置存储
    QSettings *m_settings;

    // 样式
    QString m_primaryColor;
    QString m_secondaryColor;
    QString m_backgroundColor;
    QString m_textColor;
    QString m_errorColor;
    QString m_successColor;
};

#endif // SETTINGSWIDGET_H
